import * as activeType from '../action/action-users-type'

export default function users_reducer(state = [], action) {
    switch (action.type) {
        case activeType.AddUser:
            return [...state, action.payload]
        case activeType.UpdataUser:
            return state.map(item => {
                if (item.id === action.payload.id) {
                    return {...item,...action.payload}
                } else {
                    return item
                }
            })
        case activeType.DeleteUser:
            return state.filter(item => item.id !== action.payload)
        default:
            return state
    }
}